Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Switch all markdown rendering to react-remark #2872

Merged
merged 19 commits into from
Nov 7, 2023

Conversation

danyx23
Copy link
Contributor

@danyx23 danyx23 commented Oct 30, 2023

This PR continues replacing our old custom markdown subset parser with react-remark and related functions.

We want to keep rendering markdown inside Grapher as svg text that is limited vs what markdown can offer and we have some existing svg text measuring and line break logic that we don't want to replace. To keep the changes to a relative minimum I therefore decided to translate the mdast elements to IRToken ones so that the existing logic can mostly stay in place.

Note that we are not using the latest version of mdast and related libraries as they switched to ESM only in Summer 2021 and our server admin project for example doesn't work with that yet.

The SVG tester shows quite a number of differences - I recommend reviewing the differences on the follow up branch that adds plain url parsing. Once the plain URL parsing is added, the following differences in chart subtitle/footnote rendering remain:

  • double newlines (i.e. an empty line) are converted to single newlines. I think this is better for charts
  • sometimes the line break happens a little later now which I think is also a slight improvement
  • lists show a bit weirdly (i.e. if you write in a new line 1) bla or - bla then this is now condensed into a single line and there is a weird backslash. There are 2 charts that do this that I saw in the svg tester but they are old covid charts so I think this is fine for now. We can reconsider if we want to allow lists/bullet points in subtitles in the future

@danyx23 danyx23 changed the base branch from master to markdown-add-react-remark October 30, 2023 10:33
@danyx23 danyx23 force-pushed the switch-markdown-renderer branch from 5ff3378 to b1f2f96 Compare October 30, 2023 10:33
@danyx23 danyx23 changed the title ✨ add react-remark library, test it in SimpleMarkdownText ✨ Switch all markdown rendering to react-remark Oct 30, 2023
@danyx23 danyx23 force-pushed the markdown-add-react-remark branch from 7a3fe54 to 002618e Compare October 30, 2023 14:27
@danyx23 danyx23 force-pushed the switch-markdown-renderer branch from 387b8de to 0e1f343 Compare October 30, 2023 14:27
@danyx23 danyx23 force-pushed the markdown-add-react-remark branch from 002618e to 5d10eda Compare November 1, 2023 11:55
@danyx23 danyx23 force-pushed the switch-markdown-renderer branch 2 times, most recently from 3ac6675 to e92588c Compare November 1, 2023 13:35
@danyx23 danyx23 marked this pull request as ready for review November 2, 2023 12:25
@danyx23 danyx23 requested review from marcelgerber, mlbrgl, ikesau and sophiamersmann and removed request for marcelgerber and mlbrgl November 2, 2023 12:28
Comment on lines 717 to 720
function convertMarkdownRootToIRTokens(
node: Root,
fontParams?: IRFontParams
): IRToken[] {
return node.children.flatMap((item) =>
convertMarkdownNodeToIRTokens(item, fontParams)
)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to inline this into convertMarkdownToIRTokens - but you decide :)

@marcelgerber
Copy link
Member

Just noticed that this goes wrong on http://staging-site-switch-markdown-renderer/grapher/days-since-100th-covid-case:
CleanShot 2023-11-06 at 10 41 22

@danyx23 danyx23 force-pushed the markdown-add-react-remark branch from 4dc9fe3 to 6c06232 Compare November 7, 2023 14:36
@danyx23 danyx23 force-pushed the switch-markdown-renderer branch from 01111b6 to 3e3744f Compare November 7, 2023 14:36
@@ -15,6 +15,7 @@ import { TextWrap } from "../TextWrap/TextWrap.js"
import fromMarkdown from "mdast-util-from-markdown"
import type { Root, Content } from "mdast"
import { match } from "ts-pattern"
import { dropRightWhile, dropWhile } from "lodash"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this right here will increase bundlesize quite a bit - make sure to import lodash via Util.ts always.

We should probably get rid of that annoyance at some point, but for now that's how it goes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? Our bundlewatch GA didn't show any increase. I thought that importing { _ } from "lodash" was the big no-no. What am I missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you're right!
I was missing my own change half a year ago 😬

Copy link
Contributor Author

danyx23 commented Nov 7, 2023

Merge activity

@danyx23 danyx23 force-pushed the markdown-add-react-remark branch from 6c06232 to f239a48 Compare November 7, 2023 21:02
@danyx23 danyx23 force-pushed the switch-markdown-renderer branch from 531cc39 to 3863877 Compare November 7, 2023 21:02
Base automatically changed from markdown-add-react-remark to master November 7, 2023 21:03
@danyx23 danyx23 merged commit bed3489 into master Nov 7, 2023
12 of 15 checks passed
@danyx23 danyx23 deleted the switch-markdown-renderer branch November 7, 2023 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants